package tuathal.snake;

import java.awt.Component;

public class SnakeRunnable implements Runnable {
	private Snake snake;
	private Component component;

	public SnakeRunnable(Snake snake, Component component) {
		super();
		this.snake = snake;
		this.component = component;
	}

	@Override
	public void run() {
		while (true) {
			try {
				if (snake.status == Snake.RUNNING) {
					snake.move();
					component.repaint();
					Thread.sleep(snake.speed);
				}
				if (snake.status == Snake.GAMEOVER) {
					component.repaint();
					Thread.currentThread().interrupt();
				}
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}
}
